import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;




public class Example2  extends JPanel implements ActionListener{

	int x = 0;
	int y = 0;
	Timer t;
	Timer t2;
	RectangleCharacter rc;
	public Example2(JFrame f){
		rc = new RectangleCharacter();
		t = new Timer(100, this);
		t2 = new Timer(1000, this);
		this.setBackground(Color.BLACK);
		t.addActionListener(rc);
		f.addKeyListener(rc);
		t.start();
	}

	@Override
	public void paint(Graphics g){
		Graphics2D g2d = (Graphics2D)g;
		super.paint(g2d);
		g2d.setColor(rc.getColor());
		AffineTransform prev = g2d.getTransform();
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);2
		g2d.transform(rc.getTransform());
		g2d.fill(rc.getShape());
		g2d.setTransform(prev);
	}


	public void actionPerformed(ActionEvent e){
		if(e.getSource().equals(t)){
			x += 1;
			y += 1;
			this.repaint();
		}
	}

	public static void main(String[] args){
		JFrame frame = new JFrame("title");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(1024, 720);
		frame.setResizable(false);
		Example2 ex = new Example2(frame);
		frame.add(ex);
		frame.setVisible(true);
	}
}
